{include file="public/header" /}
<span class="layui-breadcrumb">
  <a href="{:url('Blog/index')}?nav=blog-bloglist">分类</a>
  <a><cite>编辑-{$one['cname']}</cite></a>
</span>
<style> 
.layui-form-label{width:200px;}
.layui-form-item .layui-input-block{margin-left:230px;}
</style>
<div class="layui-fluid">
    <div class="layui-card">
      <form class="layui-form" id="product_form" action="" style='padding:10px'>
        <div class="layui-form-item">
              <div class="layui-input-block" style="color: red;">
                <div>规则：购买按钮仅出现在，产品的最小分类。是否显示左侧筛选按钮，仅出现在路由生成方式为index/Product/index/时，即该分类是产品</div>
                <div>
                  关于tag类型，指的是参与分类但是，不生成链接，和面包屑的这类分类，如 Miniature Bearing=>Inch Size Miniature Bearing=>Inch Standard中的Inch Size Miniature Bearing即是tag类型，tag类型的选择仅出现在，路由生成方式为index/Product/index/时，即该分类是产品
                </div>
              </div>
          </div>
      
        <div class="layui-form-item">
              <label class="layui-form-label">分类名称</label>
              <div class="layui-input-block">
                 <input type="text" id="cname" name="cname" lay-verify="title" autocomplete="off" value="{$classify['cname']}" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">分类别名(H1)</label>
              <div class="layui-input-block">
                 <input type="text" id="alias_name" name="alias_name" lay-verify="title" autocomplete="off" value="{$classify['alias_name']}" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">url</label>
              <div class="layui-input-block">
                 <input type="text" id="route_name" name="route_name" lay-verify="title" autocomplete="off" value="{$classify['route_name']}" class="layui-input">
              </div>
          </div>

           <div class="layui-form-item">
              <div class="layui-input-block" style="color: red;">
                以上三个输入的区别，分类名称为必填项。分类别名是指在前端列表显示的名称，若不填前端则显示分类名称。url若不填则为分类名称的小写且替换所有符号为中划线，若填写则url更改为填写的url，url规则必须是小写且只能有一种符号：中划线
              </div>
          </div>
           <div class="layui-form-item">
            <label class="layui-form-label">路由选择</label>
            <div class="layui-input-block">
              <select name="route_id" >
                {foreach $route as $key=>$value }
                <?php if($classify['route_id']!=$value['id']){?>
                <option value="{$value['id']}">{$value['mvc']}</option>
                <?php }else{ ?>
                <option value="{$value['id']}" selected="">{$value['mvc']}</option>
                <?php } ?>
                {/foreach}
               
              </select>
            </div>
          </div>
          <div class="layui-form-item">
              <div class="layui-input-block" style="color: red;">
                路由指的是：生成url的方式，以上所有选择项目，只有两种常用的即‘index/Product/index/’和‘index/Dan/index/’分别为产品列表的url生成方式和单页面的url生成方式
              </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">图片</label>
            <div class="layui-input-block">
              <div class="layui-upload">
              <button type="button" class="layui-btn layui-btn-xs" id="upload_img">选择图片</button>
              <span style='color:#FF5722;font-size:12px'>视频及ie8不支持预览</span>
              <div class="layui-upload-list">
                <?php if(!empty($classify['img'])){ ?>
                <img class="layui-upload-img" style='width:200px' id="show_img" src="{:Config::get('app.images_host')}{$classify['img']}">
                <?php }else{ ?>
                <img class="layui-upload-img" style='width:200px' id="show_img" src="">
                <?php } ?>
                <p id="demoText"></p>
              </div>
            </div> 
            </div>
            <?php if(!empty($classify['img'])){ ?>
            <input type="text" name="newname" style="display:none" value="{$classify['img']}">
            <?php }else{ ?>
            <input type="text" name="newname" style="display:none" value="">
            <?php } ?>
          </div>
          <?php 
            $min_class=Db::table('lily_classify')->field('id')->where('fid',$one['id'])->find();
            $f_class=Db::table('lily_classify')->field('cname,seq,id')->where([['fid','=',$one['fid']],['status','<>',0],['is_show','=',1]])->order('seq')->select();
            if(empty($min_class)&&$one['route_id']==2){
          ?>
          <div class="layui-form-item">
            <label class="layui-form-label">是否可购买</label>
            <div class="layui-input-block">
              <?php if($classify['is_pay']==0){?>
              <input type="radio" name="is_pay" value="0" title="否" checked>
              <?php }else{ ?>
              <input type="radio" name="is_pay" value="0" title="否">
              <?php } ?>
              <?php if($classify['is_pay']==1){?>
              <input type="radio" name="is_pay" value="1" title="是" checked>
              <?php }else{ ?>
              <input type="radio" name="is_pay" value="1" title="是">
              <?php } ?>
            </div>
          </div>
          <?php } ?>  


          <div class="layui-form-item">
            <label class="layui-form-label">是否生成站点地图</label>
            <div class="layui-input-block">
              <?php if($classify['is_sitemap']==0){?>
              <input type="radio" name="is_sitemap" value="0" title="否" checked>
              <?php }else{ ?>
              <input type="radio" name="is_sitemap" value="0" title="否">
              <?php } ?>
              <?php if($classify['is_sitemap']==1){?>
              <input type="radio" name="is_sitemap" value="1" title="是" checked>
              <?php }else{ ?>
              <input type="radio" name="is_sitemap" value="1" title="是">
              <?php } ?>
            </div>
          </div>

          <?php if($one['route_id']==2){?>
          <div class="layui-form-item">
            <label class="layui-form-label">是否显示左侧筛选</label>
            <div class="layui-input-block">
              <?php if($classify['is_show_left']==0){?>
              <input type="radio" name="is_show_left" value="0" title="否" checked>
              <?php }else{ ?>
              <input type="radio" name="is_show_left" value="0" title="否">
              <?php } ?>
              <?php if($classify['is_show_left']==1){?>
              <input type="radio" name="is_show_left" value="1" title="是" checked>
              <?php }else{ ?>
              <input type="radio" name="is_show_left" value="1" title="是">
              <?php } ?>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">是否是tag类型</label>
            <div class="layui-input-block">
              <?php if($classify['is_tag']==0){?>
              <input type="radio" name="is_tag" value="0" title="否" checked>
              <?php }else{ ?>
              <input type="radio" name="is_tag" value="0" title="否">
              <?php } ?>
              <?php if($classify['is_tag']==1){?>
              <input type="radio" name="is_tag" value="1" title="是" checked>
              <?php }else{ ?>
              <input type="radio" name="is_tag" value="1" title="是">
              <?php } ?>
            </div>
          </div>
          <?php } ?>

           <div class="layui-form-item">
            <label class="layui-form-label">是否前端显示</label>
            <div class="layui-input-block">
              <?php if($classify['is_show']==0){?>
              <input type="radio" name="is_show" value="0" title="否" checked>
              <?php }else{ ?>
              <input type="radio" name="is_show" value="0" title="否">
              <?php } ?>
              <?php if($classify['is_show']==1){?>
              <input type="radio" name="is_show" value="1" title="是" checked>
              <?php }else{ ?>
              <input type="radio" name="is_show" value="1" title="是">
              <?php } ?>
            </div>
          </div>


      <div class="layui-form-item">
              <label class="layui-form-label">排序</label>
              <div class="layui-input-block">
                 <div style='color: red;'>排序指的是当前的分类，在他的父类中，第几个显示在前端，按数字从小到大</div>
                 <div>已存在的有： 
                  {foreach $f_class as $key=>$value }
                  <?php if($value['id']==$one['id']){?>
                  <span style="margin-left:10px">{$value['cname']} -- {$value['seq']}</span>
                  <?php }else{?>
                  <span style="margin-left:10px"><a target='_blank' href="/admin/classify/edit_class.html?nav=classify-classifylist&id={$value['id']}" style="color:#36648a">{$value['cname']}</a> -- {$value['seq']}</span>
                  <?php } ?>
                  {/foreach}    
                </div>
                <input type="text" id="seq" name="seq" lay-verify="title" autocomplete="off" value="{$classify['seq']}" placeholder="请输入数字" class="layui-input">
                <div>父类为：<?php $f_class_d=Db::table('lily_classify')->field('id,cname')->where('id',$one['fid'])->find(); ?> 
                  <?php if(!empty($f_class_d)){?>
                  <a target='_blank' style="color:#36648a" href="/{:get_class_uplower_url($f_class_d['id'])}">{$f_class_d['cname']}</a>
                  <?php } ?>
                </div>
              </div>
          </div>



        <div class="layui-form-item">
          <label class="layui-form-label"></label>
          <div class="layui-input-block">
             <button type='button' class="layui-btn layui-btn-normal" onclick="tijiao({$one['id']})">确定</button>
          </div>
        </div>
         <div class="layui-form-item">
              <div class="layui-input-block">
                页面链接 : <a style="color: #36648a" href="/{:get_class_uplower_url($one['id'])}" target='_blank'>{$one['cname']}</a>
              </div>
          </div>

    </form>
    </div>
</div>
{include file="/public/footer" /}
<script>
layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#upload_img'
    ,accept: 'file'
    ,url: "{:url('index/Oos/upload_classdes')}" //改成您自己的上传接口
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#show_img').attr('src', result); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.status == '0'){
        return layer.msg(res.msg);
      }else{ //上传成功
        var images_host="{:Config::get('app.images_host')}";
        var images_host_re=res.url.replace(images_host,'');
        $("input[name='newname']").val(images_host_re);
        return layer.msg(res.msg);
      }
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
});  

function tijiao(id){
    layer.load();
      var cname=$.trim($("input[name='cname']").val());
      var route_name=$.trim($("input[name='route_name']").val());
      var alias_name=$.trim($("input[name='alias_name']").val());
      var seq=$.trim($("input[name='seq']").val());
      var route_id=$.trim($("select[name='route_id']").val());
      var is_pay=$.trim($("input[name='is_pay']:checked").val());
      var is_tag=$.trim($("input[name='is_tag']:checked").val());
      var is_show=$.trim($("input[name='is_show']:checked").val());
      var is_sitemap=$.trim($("input[name='is_sitemap']:checked").val());
      var is_show_left=$.trim($("input[name='is_show_left']:checked").val());
      var img=$.trim($("input[name='newname']").val());


    if(cname==''){
      layer.closeAll();
      layer.msg('分类名称必填');
      return false;
    }


    $.post("{:url('Classify/edit_class')}",{id:id,
      cname:cname,
      route_name:route_name,
      alias_name:alias_name,
      seq:seq,
      route_id:route_id,
      is_pay:is_pay,
      is_tag:is_tag,
      is_show:is_show,
      is_sitemap:is_sitemap,
      is_show_left:is_show_left,
      img:img
    },function(res){
      if(res.status=='0'){
        layer.closeAll('loading');
        layer.msg(res.msg);
      }
      if(res.status=='1'){
        layer.msg(res.msg,{time: 500 },
        function(){
          layer.closeAll();
          location.href=location.href;
        });
      }
    })
 }
</script>
